package com.wsz.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wsz.eduservice.pojo.Teacher;
import com.wsz.eduservice.service.TeacherService;
import com.wsz.eduservice.mapper.TeacherMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author wangs
* @description 针对表【edu_teacher(讲师)】的数据库操作Service实现
* @createDate 2022-09-14 20:56:24
*/
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher>
    implements TeacherService{

    @Cacheable(key = "'selectTeacher'",value = "Teacher")
    @Override
    public List<Teacher> getTeacherIndex() {
        QueryWrapper<Teacher> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.orderByDesc("id");
        queryWrapper1.last("limit 4");

        return this.list(queryWrapper1);
    }

    @Override
    public Map<String, Object> getTeacherFrontList(Page<Teacher> pageTeacher) {

        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("sort");

        baseMapper.selectPage(pageTeacher, queryWrapper);

        List<Teacher> records = pageTeacher.getRecords();
        long current = pageTeacher.getCurrent();
        long pages = pageTeacher.getPages();
        long size = pageTeacher.getSize();
        long total = pageTeacher.getTotal();
        boolean hasNext = pageTeacher.hasNext();
        boolean hasPrevious = pageTeacher.hasPrevious();

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("items", records);
        map.put("current", current);
        map.put("pages", pages);
        map.put("size", size);
        map.put("total", total);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return map;
    }
}




